﻿@model IEnumerable<PersonalWebsite.Models.Article>

@{
    ViewBag.Title = "Index";
}

<table class="layui-table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.ArticleType)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.ArticleDate)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.ArticleContent)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Markdown)
            </th>
            <th></th>
        </tr>
    </thead>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.ArticleType)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ArticleDate)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ArticleContent)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Markdown)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.ArticleID }) |
            @Html.ActionLink("Details", "Details", new { id=item.ArticleID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ArticleID })
        </td>
    </tr>
}

</table>

<script>
    function getTdValue() {
        var tableID = document.getElementsByClassName("layui-table")[0];
        for (var i = 1; i < tableID.rows.length; i++) {
            // 若ArticleContent和Markdown长度大于64个字符，则截取前64个字符显示
            var ArticleContent = tableID.rows[i].cells[2].innerHTML.trim();
            var Markdown = tableID.rows[i].cells[3].innerHTML.trim();
            if (ArticleContent.length > 64 || Markdown.length > 64) {
                tableID.rows[i].cells[2].innerHTML = ArticleContent.substring(0, 64) + "......";
                tableID.rows[i].cells[3].innerHTML = Markdown.substring(0, 64) + "......";
            }
        }
    }

    getTdValue();
</script>